package com.egoo.ticket.server.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.egoo.ticket.server.dao.*;
import com.egoo.ticket.server.pojo.dto.PageOutputDto;
import com.egoo.ticket.server.pojo.dto.WorkOrderSelectInputDto;
import com.egoo.ticket.server.pojo.dto.WorkOrderTypeAndFilterDto;
import com.egoo.ticket.server.pojo.dto.WorkOrderTypeMenuInputDto;
import com.egoo.ticket.server.pojo.entity.EwsUser;
import com.egoo.ticket.server.pojo.entity.WorkOrderStatus;
import com.egoo.ticket.server.pojo.entity.WorkOrderTypeMenu;
import com.egoo.ticket.server.pojo.vo.TypeMenuAndFilterMenu;
import com.egoo.ticket.server.pojo.vo.VisibleRangeVo;
import com.egoo.ticket.server.pojo.vo.WorkOrderFilterMenuVo;
import com.egoo.ticket.server.service.*;
import com.egoo.ticket.server.utils.common.CommonUtil;
import com.egoo.ticket.server.utils.common.ConstantCode;
import com.egoo.ticket.server.utils.common.DbResponse;
import com.egoo.ticket.server.utils.common.ResponseConstant;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;

/**
 * @author Administrator
 */
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class WorkOrderTypeMenuServiceImpl implements WorkOrderTypeMenuService {

	@Autowired
	private WorkOrderTypeMenuDao workOrderTypeMenuDao;
	@Autowired
	private EwsUserDao ewsUserDao;
	@Autowired
	private WorkOrderFilterMenuDao workOrderFilterMenuDao;
	@Autowired
	private UserRoleService userRoleService;
	@Autowired
	private EwsRoleDao ewsRoleDao;
	@Autowired
	private EwsDepartmentDao ewsDepartmentDao;
	@Autowired
	private WorkOrderStatusDao workOrderStatusDao;
	@Autowired
	private RoleService roleService;
	@Autowired
	private UserService userService;
	@Autowired
	private DepartmentService departmentService;
	@Autowired
	private CommonUtil commonUtil;
	@Autowired
	private WorkOrderService workOrderService;
	@Autowired
	private WorkOrderDao workOrderDao;

	/**
	 * 根据工单类型菜单名称进行模糊查询分页
	 *
	 * @param menuName
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@Override
	public DbResponse selectByName(String menuName, Integer currentPage, Integer pageSize, String tenantId) {
		// 设置分页参数
		PageHelper.startPage(currentPage,pageSize);
		List<WorkOrderTypeMenu> workOrderTypeMenuList = workOrderTypeMenuDao.selectByName(menuName,tenantId);
		// 获取总数
		PageInfo<WorkOrderTypeMenu> pageInfo = new PageInfo<>(workOrderTypeMenuList);
		return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,
				ResponseConstant.SELECT_SUCCESS_MSG,handleWorkOrderTypeMenuListData(workOrderTypeMenuList,tenantId),pageInfo.getTotal());

	}
	/**
	 * TODO 处理工单类型菜单列表数据
	 * @author: victor_tang
	 * @createtime: 2020/2/7 11:30
	 * @param workOrderTypeMenuList 1
	 * @return: java.utils.List<com.egoo.ews.service.vo.WorkOrderTypeMenu>
	 */
	private List<WorkOrderTypeMenu> handleWorkOrderTypeMenuListData(List<WorkOrderTypeMenu> workOrderTypeMenuList,String tenantId){
		for (WorkOrderTypeMenu workOrderTypeMenu : workOrderTypeMenuList) {

			String menuVisibleNames = translateMenuVisibleName(workOrderTypeMenu.getMenuVisibleType(),
					workOrderTypeMenu.getMenuVisibleIds(),tenantId);

			workOrderTypeMenu.setMenuVisibleNames(menuVisibleNames);
		}
		return workOrderTypeMenuList;
	}
	/**
	 * TODO 翻译可见性范围ids为names
	 * @author: victor_tang
	 * @createtime: 2020/2/7 11:33
	 * @param menuVisibleType 1
	 * @param menuVisibleIds 2
	 * @return: java.lang.String
	 */
	@Override
	public String translateMenuVisibleName(String menuVisibleType,String menuVisibleIds,String tenantId){

		List<String> menuVisibleIdsList = null;

		if (StringUtils.isNotBlank(menuVisibleIds)){
			 if (ConstantCode.UserRoleDeptType.DEPT.equals(menuVisibleType)) {
				 menuVisibleIdsList = commonUtil.splitDeptCode(menuVisibleIds);
			 }else {
				 menuVisibleIdsList =Arrays.asList(menuVisibleIds.split(","));
			 }
		}
		if (ConstantCode.UserRoleDeptType.ALL.equals(menuVisibleType)) {

			return ConstantCode.UserRoleDeptType.ALL_ZH;
		}
		else if(ConstantCode.UserRoleDeptType.DEPT.equals(menuVisibleType)){

			return departmentService.getNamesByDeptIds(menuVisibleIdsList,tenantId);
		}
		else if(ConstantCode.UserRoleDeptType.ROLE.equals(menuVisibleType)){

			return roleService.getNamesByRoleIds(menuVisibleIdsList,tenantId);
		}
		else if(ConstantCode.UserRoleDeptType.USER.equals(menuVisibleType)){

			return userService.getNamesByUserIds(menuVisibleIdsList,tenantId);
		}
		return null;
	}
	/**
	 * 查询全部的工单类型菜单信息分页
	 *
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@Override
	public PageOutputDto selectAll(Integer currentPage, Integer pageSize, String tenantId) {
		PageOutputDto pageOutputDto = new PageOutputDto();
		List<WorkOrderTypeMenu> workOrderTypeMenuList = workOrderTypeMenuDao.selectAll((currentPage - 1) * pageSize,
				pageSize,tenantId);
		Integer toatal = workOrderTypeMenuDao.selectTotal(tenantId);
		pageOutputDto.setList(workOrderTypeMenuList);
		pageOutputDto.setTotal(toatal);
		return pageOutputDto;
	}

	/**
	 * 根据工单类型菜单Id获取工单类型菜单信息
	 *
	 * @param id
	 * @return
	 */
	@Override
	public WorkOrderTypeMenu selectById(Integer id,String tenantId) {
		return  workOrderTypeMenuDao.selectById(id,tenantId);
	}

	/**
	 * 更新工单类型菜单的使用状态
	 *
	 * @param id
	 * @param userId
	 * @param status
	 * @return
	 */
	@Override
	public Integer updateUseStatus(Integer id, String userId, Integer status,String tenantId) {
		WorkOrderTypeMenu workOrderTypeMenu = workOrderTypeMenuDao.selectById(id,tenantId);
		EwsUser ewsUser = ewsUserDao.selectById(userId);
		workOrderTypeMenu.setLastUserId(userId);
		workOrderTypeMenu.setLastUserName(ewsUser.getName());
		Timestamp time = new Timestamp(System.currentTimeMillis());
		workOrderTypeMenu.setLastUpdateTime(time);
		workOrderTypeMenu.setStatus(status);
		return workOrderTypeMenuDao.updateUseStatus(workOrderTypeMenu);
	}

	/**
	 * 新建工单类型菜单
	 *
	 * @param workOrderTypeMenuInputDto
	 * @return
	 */
	@Override
	public Integer insertMenu(WorkOrderTypeMenuInputDto workOrderTypeMenuInputDto) {
		WorkOrderTypeMenu workOrderTypeMenu = new WorkOrderTypeMenu();
		// 工单类型可见性数据组装
		VisibleRangeVo visibleRange = workOrderTypeMenuInputDto.getVisibleRange();
		if (visibleRange!=null) {
			String type = visibleRange.getType();
			workOrderTypeMenu.setMenuVisibleType(type);
			JSONArray menuVisibleIdList = visibleRange.getValue();
			String menuVisibleIdStr = null;
			if (ConstantCode.UserRoleDeptType.DEPT.equals(type)) {
				menuVisibleIdStr = menuVisibleIdList.toJSONString();
			}else{
				menuVisibleIdStr = StringUtils.join(menuVisibleIdList, ",");
			}
			workOrderTypeMenu.setMenuVisibleIds(menuVisibleIdStr);
		}
		String userId = workOrderTypeMenuInputDto.getUserId();
		// 获取当前用户信息
		EwsUser ewsUser = ewsUserDao.selectById(userId);
		String ewsUserName = ewsUser.getName();

		workOrderTypeMenu.setMenuName(workOrderTypeMenuInputDto.getMenuName());
		workOrderTypeMenu.setMenuDesc(workOrderTypeMenuInputDto.getMenuDesc());
		workOrderTypeMenu.setOrdering(workOrderTypeMenuInputDto.getOrdering());
		workOrderTypeMenu.setStatus(workOrderTypeMenuInputDto.getStatus());
		workOrderTypeMenu.setLastUserId(userId);
		Timestamp time = new Timestamp(System.currentTimeMillis());
		workOrderTypeMenu.setLastUpdateTime(time);
		workOrderTypeMenu.setWorkOrderTypeId(workOrderTypeMenuInputDto.getWorkOrderTypeId());
		workOrderTypeMenu.setWorkOrderTypeName(workOrderTypeMenuInputDto.getWorkOrderTypeName());
		workOrderTypeMenu.setCreateTime(time);
		workOrderTypeMenu.setCreateUserId(userId);
		workOrderTypeMenu.setCreateUserName(ewsUserName);
		workOrderTypeMenu.setLastUserName(ewsUserName);
		workOrderTypeMenu.setTagId(workOrderTypeMenuInputDto.getTagId());
		workOrderTypeMenu.setTagName(workOrderTypeMenuInputDto.getTagName());
		workOrderTypeMenu.setTenantId(workOrderTypeMenuInputDto.getTenantId());
		workOrderTypeMenu.setId(workOrderTypeMenuInputDto.getId());
		Integer result = workOrderTypeMenuDao.insertMenu(workOrderTypeMenu);
		return result;
	}

	/**
	 * 编辑工单类型菜单
	 *
	 * @param workOrderTypeMenuInputDto
	 * @return
	 */
	@Override
	public Integer updateContent(WorkOrderTypeMenuInputDto workOrderTypeMenuInputDto) {
		Integer id = workOrderTypeMenuInputDto.getId();
		String tenantId = workOrderTypeMenuInputDto.getTenantId();
		WorkOrderTypeMenu workOrderTypeMenu = workOrderTypeMenuDao.selectById(id,tenantId);
		VisibleRangeVo visibleRange = workOrderTypeMenuInputDto.getVisibleRange();
		String type = visibleRange.getType();
		workOrderTypeMenu.setMenuVisibleType(type);
		JSONArray menuVisibleIdList = visibleRange.getValue();
		String menuVisibleIdStr = null;
		if (ConstantCode.UserRoleDeptType.DEPT.equals(type)) {
			menuVisibleIdStr = menuVisibleIdList.toJSONString();
		}else{
			menuVisibleIdStr = StringUtils.join(menuVisibleIdList, ",");
		}
		workOrderTypeMenu.setMenuVisibleIds(menuVisibleIdStr);
//		String nameList = "";
//		JSONObject visibleRange1 = JSONObject.parseObject(JSON.toJSONString(visibleRange));
//		if (visibleRange1.getString("type").equals(ConstantCode.UserRoleDeptType.ALL)) {
//			workOrderTypeMenu.setVisibleRange(visibleRange1);
//		}
//		else if (visibleRange1.getString("type").equals(ConstantCode.UserRoleDeptType.USER)) {
//			for (int i = 0; i < visibleRange1.getJSONArray("value").size(); i++) {
//				EwsUser ewsUser = ewsUserDao.selectById((visibleRange1.getJSONArray("value").getInteger(i).toString()));
//				if (i == 0) {
//					nameList += ewsUser.getName();
//				} else {
//					nameList += "," + ewsUser.getName();
//				}
//
//			}
//			visibleRange.setNameList("" + nameList);
//			JSONObject visibleRange2 = JSONObject.parseObject(JSON.toJSONString(visibleRange));
//			workOrderTypeMenu.setVisibleRange(visibleRange2);
//		}
//		else if(visibleRange1.getString("type").equals(ConstantCode.UserRoleDeptType.ROLE)){
//			for (int i = 0; i < visibleRange1.getJSONArray("value").size(); i++) {
//				EwsRole ewsRole = ewsRoleDao.selectByRoleId((visibleRange1.getJSONArray("value").getInteger(i).toString()));
//				if (i == 0) {
//					nameList += ewsRole.getName();
//				} else {
//					nameList += "," + ewsRole.getName();
//				}
//			}
//			visibleRange.setNameList("" + nameList);
//			JSONObject visibleRange2 = JSONObject.parseObject(JSON.toJSONString(visibleRange));
//			workOrderTypeMenu.setVisibleRange(visibleRange2);
//		}
//		else if(visibleRange1.getString("type").equals(ConstantCode.UserRoleDeptType.DEPT)){
//			for (int i = 0; i < visibleRange1.getJSONArray("value").size(); i++) {
//				EwsRole ewsRole = ewsRoleDao.selectByRoleId((visibleRange1.getJSONArray("value").getInteger(i).toString()));
//				if (i == 0) {
//					nameList += ewsRole.getName();
//				} else {
//					nameList += "," + ewsRole.getName();
//				}
//			}
//			visibleRange.setNameList("" + nameList);
//			JSONObject visibleRange2 = JSONObject.parseObject(JSON.toJSONString(visibleRange));
//			workOrderTypeMenu.setVisibleRange(visibleRange2);
//		}

		workOrderTypeMenu.setMenuDesc(workOrderTypeMenuInputDto.getMenuDesc());
		workOrderTypeMenu.setStatus(workOrderTypeMenuInputDto.getStatus());
		workOrderTypeMenu.setMenuName(workOrderTypeMenuInputDto.getMenuName());
		workOrderTypeMenu.setOrdering(workOrderTypeMenuInputDto.getOrdering());
		String userId = workOrderTypeMenuInputDto.getUserId();
		// 获取当前用户信息
		EwsUser ewsUser = ewsUserDao.selectById(userId);
		workOrderTypeMenu.setLastUserId(userId);
		workOrderTypeMenu.setLastUserName(ewsUser.getName());
		Timestamp time = new Timestamp(System.currentTimeMillis());
		workOrderTypeMenu.setLastUpdateTime(time);
		return  workOrderTypeMenuDao.updateContent(workOrderTypeMenu);
	}

	/**
	 * 返回当前排序最大值+1
	 *
	 * @return
	 */
	@Override
	public Integer selectOrderMax() {
		Integer count = 0;
		List<WorkOrderTypeMenu> workOrderTypeMenuList = workOrderTypeMenuDao.selectAllMenu();
		if (null != workOrderTypeMenuList && !workOrderTypeMenuList.isEmpty()) {
			count = workOrderTypeMenuDao.selectOrderMax() + 1;
			return count;
		}
		count = count + 1;
		return count;
	}

	/**
	 * 根据工单类型名称获取工单类型菜单信息（不是模糊查询）
	 *
	 * @param menuName
	 * @return
	 */
	@Override
	public WorkOrderTypeMenu selectByEqualsName(String menuName,String tenantId) {
		return workOrderTypeMenuDao.selectByEqualsName(menuName,tenantId);
	}

	/**
	 * 根据状态排序获取工单类型菜单信息
	 *
	 * @param ordering
	 * @return
	 */
	@Override
	public WorkOrderTypeMenu selectByOrdering(Integer ordering) {
		return workOrderTypeMenuDao.selectByOrdering(ordering);
	}

	/**
	 * TODO 获取工单状态名称
	 *
	 * @param condition 1
	 * @author: victor_tang
	 * @createtime: 2019/10/5 11:53
	 * @return: java.lang.String
	 */
	private String getStatusName(JSONObject condition,String tenantId) {
		// 获取过滤器一级下拉选中的value
		JSONObject firstIdJsonObj = condition.getJSONObject("firstId");
		Integer filterFirstValue = null;
		if (!firstIdJsonObj.isEmpty()) {
			filterFirstValue = firstIdJsonObj.getInteger("value");
		}

		// 获取过滤三级下拉选中id
		JSONObject filterThirdJsonObj = condition.getJSONObject("secondDataId");
		Integer filterThirdValue = null;
		if (!filterThirdJsonObj.isEmpty()) {
			filterThirdValue = filterThirdJsonObj.getInteger("value");
		}

		// 判断过滤器条件是否选择工单状态 此处5代表工单状态，1代表是，在数据初始化时写死的
		if (5 == filterFirstValue && 1 == filterThirdValue) {
			// 确定此过滤器包含工单状态条件,获取工单状态名称
			String stateIdStr = condition.getString("value");

			WorkOrderStatus workOrderStatus = workOrderStatusDao.selectById(Integer.valueOf(stateIdStr),tenantId);

			return workOrderStatus != null ? workOrderStatus.getName() : null;
		}
		return null;
	}

	/**
	 * TODO 获取过滤器条件工单状态名称
	 *
	 * @param condition 过滤器条件
	 * @author: victor_tang
	 * @createtime: 2019/10/5 10:58
	 * @return: java.lang.String
	 */
	private String getFilterConditionStatusName(JSONObject condition,String tenantId) {
		if (condition ==null || condition.isEmpty()) {
			return null;
		}
		JSONArray conditionJsonArray = condition.getJSONArray("condition");

		for (int i = 0; i < conditionJsonArray.size(); i++) {
			JSONObject conditionJSONObject = conditionJsonArray.getJSONObject(i);
			// 获取过滤器工单状态名称
			String statusName = getStatusName(conditionJSONObject,tenantId);
			if (StringUtils.isNotBlank(statusName)) {
				return statusName;
			}
		}
		return null;
	}
	/**
	 * TODO 获取该用户可见的所有工单类型菜单及过滤器菜单列表
	 * @author: victor_tang
	 * @createtime: 2020/2/6 15:31
	 * @param userId 1
	 * @return: java.utils.List<com.egoo.ews.service.dto.WorkOrderTypeAndFilterDto>
	 */
	@Override
	public List<WorkOrderTypeAndFilterDto> getTypeMenuAndFilterMenuListByUserId(String userId, String tenanId) {
		// 获取该用户可见的所有工单类型菜单及过滤器菜单原始数据
		List<TypeMenuAndFilterMenu> typeMenuAndFilterMenuList =
				workOrderTypeMenuDao.selectTypeMenuAndFilterMenuList(userId,tenanId);

		// 筛选工单类型菜单id
		LinkedHashSet<Integer> workOrderTypeMenuIdSet = new LinkedHashSet<>();
		for (TypeMenuAndFilterMenu typeMenuAndFilterMenu : typeMenuAndFilterMenuList) {
			workOrderTypeMenuIdSet.add(typeMenuAndFilterMenu.getTypeMenuId());
		}

		// 返回给前台展示的list类型的dto对象
		List<WorkOrderTypeAndFilterDto> workOrderTypeAndFilterDtoList = new ArrayList<>();

		// 根据工单类型菜单id过滤数据
		for (Integer  typeMenuId: workOrderTypeMenuIdSet) {

			WorkOrderTypeAndFilterDto workOrderTypeAndFilterDto =
					handleFilterMenuDataByTypeMenuId(userId,tenanId,
							typeMenuId, typeMenuAndFilterMenuList);

			workOrderTypeAndFilterDtoList.add(workOrderTypeAndFilterDto);

		}
		return workOrderTypeAndFilterDtoList;
	}

	/**
	 * TODO 根据工单类型菜单id筛选数据
	 * @author: victor_tang
	 * @createtime: 2020/2/6 17:40
	 * @param typeMenuId 1
	 * @param typeMenuAndFilterMenuList 2
	 * @return: com.egoo.ews.service.dto.WorkOrderTypeAndFilterDto
	 */
	private WorkOrderTypeAndFilterDto handleFilterMenuDataByTypeMenuId(String userId,String tenantId,
																	   Integer typeMenuId,List<TypeMenuAndFilterMenu> typeMenuAndFilterMenuList){
		WorkOrderTypeMenu workOrderTypeMenu = workOrderTypeMenuDao.selectById(typeMenuId,tenantId);

		// 组装工单类型菜单信息
		WorkOrderTypeAndFilterDto workOrderTypeAndFilterDto = new WorkOrderTypeAndFilterDto();
		workOrderTypeAndFilterDto.setId(typeMenuId);
		workOrderTypeAndFilterDto.setMenuName(workOrderTypeMenu.getMenuName());

		// 筛选组装该工单类型菜单下的过滤器数据
		List<WorkOrderFilterMenuVo> workOrderFilterMenuList = new ArrayList<>();
		for (TypeMenuAndFilterMenu typeMenuAndFilterMenu : typeMenuAndFilterMenuList) {
			if (!typeMenuId.equals(typeMenuAndFilterMenu.getTypeMenuId())) {
				continue;
			}
			WorkOrderFilterMenuVo workOrderFilterMenuVo =
					handleFilterMenuData(userId,tenantId,typeMenuAndFilterMenu);
			if (workOrderFilterMenuVo!=null) {
				workOrderFilterMenuList.add(workOrderFilterMenuVo);
			}

		}
		// 设置过滤器菜单列表数据
		workOrderTypeAndFilterDto.setWorkOrderFilterMenuList(workOrderFilterMenuList);
		return workOrderTypeAndFilterDto;
	}
	/**
	 * TODO 组装过滤器菜单数据
	 * @author: victor_tang
	 * @createtime: 2020/3/28 11:13
	 * @param userId 1
	 * @param tenantId 2
	 * @param typeMenuAndFilterMenu 3
	 * @return: com.egoo.ews.service.vo.WorkOrderFilterMenuVo
	 */
	private WorkOrderFilterMenuVo handleFilterMenuData(String userId, String tenantId,
													   TypeMenuAndFilterMenu typeMenuAndFilterMenu){
		if (typeMenuAndFilterMenu.getFilterMenuId()==null) {
			return null;
		}
		Integer filterId = typeMenuAndFilterMenu.getFilterMenuId();
		WorkOrderFilterMenuVo workOrderFilterMenuVo = new WorkOrderFilterMenuVo();

		workOrderFilterMenuVo.setId(filterId);
		workOrderFilterMenuVo.setName(typeMenuAndFilterMenu.getFileterMenuName());
		workOrderFilterMenuVo.setWorkOrderTypeId(typeMenuAndFilterMenu.getWorkOrderTypeId());
		// 获取该过滤器下的工单或者服务单总数量
		Long count = getWorkOrderCountOfFilter(userId, tenantId,filterId);
		workOrderFilterMenuVo.setCount(count);
		// 获取过滤器条件工单状态名称
		String filterConditionStatusName = getFilterConditionStatusName(typeMenuAndFilterMenu.getFilterCondition(),tenantId);
		workOrderFilterMenuVo.setConditionStatusName(filterConditionStatusName);

		return workOrderFilterMenuVo;
	}
	/**
	 * TODO 获取过滤器下的工单总数
	 * @author: victor_tang
	 * @createtime: 2020/3/28 10:53
	 * @param userId 1
	 * @param tenantId 2
	 * @param filterId 3
	 * @return: long
	 */
	private Long getWorkOrderCountOfFilter(String userId,String tenantId,
										Integer filterId){
		// 非待处理服务单和待处理工单的过滤器，直接跳过
		if (ConstantCode.SysFilter.WAIT_HANDLE_FILTER_ID!=filterId
		) {
			return null;
		}
		WorkOrderSelectInputDto dto = new WorkOrderSelectInputDto();
		dto.setUserId(userId);
		dto.setTenantId(tenantId);
		dto.setWorkOrderFilterId(filterId);
		String sql = workOrderService.joinSqlContion(dto)
		.replace("select a.*,"+
						"b.work_order_id,b.urge_count,b.redeploy_count,b.contact_work_order_id_str,b.is_time_out,b.session_id,b.external_work_order_id,b.work_order_monitor_id,b.merge_base_work_order_ids,b.is_recieve,b.sender,b.is_children " +
						"from work_order a,work_order_relation b ",
				"select count(*) from work_order a,work_order_relation b ");
		return workOrderDao.selectCountBySql(sql);
	}

	/**
	 * 提供更新工单类型信息接口
	 *
	 * @param userId
	 * @param workOrderTypeIdSrc 原工单类型Id
	 * @param workOrderTypeName  修改后工单类型名字
	 * @return
	 */
	@Override
	public Integer updateWorkOrderType(String userId, Long workOrderTypeIdSrc, String workOrderTypeName,String tenantId) {
		WorkOrderTypeMenu workOrderTypeMenu = workOrderTypeMenuDao.selectByWorkOrderTypeId(workOrderTypeIdSrc,tenantId);
		EwsUser ewsUser = ewsUserDao.selectById(userId);
		workOrderTypeMenu.setLastUserId(userId);
		workOrderTypeMenu.setLastUserName(ewsUser.getName());
		Timestamp time = new Timestamp(System.currentTimeMillis());
		workOrderTypeMenu.setLastUpdateTime(time);
		workOrderTypeMenu.setWorkOrderTypeName(workOrderTypeName);
		workOrderTypeMenu.setMenuName(workOrderTypeName);
		workOrderTypeMenu.setWorkOrderTypeId(workOrderTypeIdSrc);
		return workOrderTypeMenuDao.updateWorkOrderType(workOrderTypeMenu);
	}
}
